package cn.wps.sdk.demo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioGroup;
import androidx.annotation.Nullable;
import cn.wps.moffice.sdk.WpsSdk;
import cn.wps.moffice.sdk.api.bean.FileType;
import cn.wps.moffice.sdk.api.common.FileApi;
import cn.wps.sdk.demo.R;

public class NewDocumentActivity extends Activity {
    private RadioGroup rg_file_type;
    private Button btn_newFile;
    private FileType fileType = FileType.WPS;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_document);
        rg_file_type = findViewById(R.id.rg_file_type);
        btn_newFile = findViewById(R.id.btn_newFile);
        rg_file_type.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rb_wps) {
                fileType = FileType.WPS;
            } else if (checkedId == R.id.rb_et) {
                fileType = FileType.ET;
            } else if (checkedId == R.id.rb_wpp) {
                fileType = FileType.WPP;
            }
        });

        btn_newFile.setOnClickListener(view ->
        {
            newFile();
        });
    }

    private void newFile() {
        FileApi fileApi = WpsSdk.getInstance().getApi(FileApi.class);
        if (fileApi != null) {
            fileApi.newFile(NewDocumentActivity.this, fileType);
        }
    }

}
